﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Kiiro.Common.Interfaces;
using Kiiro.Common.Utility;

namespace Kiiro.Common.Entities
{
    [Serializable]
    public class Project : BaseEntity, IEntity
    {
        #region Private Properties

        private DateTime startDate;
        private List<ValidationMessage> startDateMessage = new List<ValidationMessage> ( );
        private DateTime endDate;
        private List<ValidationMessage> endDateMessage = new List<ValidationMessage> ( );
        private ProjectStatus projectStatus;
        private List<ValidationMessage> projectStatusMessage = new List<ValidationMessage> ( );
        private TimeMetric timeMetric;
        private List<ValidationMessage> timeMetricMessage = new List<ValidationMessage> ( );
        private string summaryNote;
        private List<ValidationMessage> summaryNoteMessage = new List<ValidationMessage> ( );
        private string projectPlanFileUrl;
        private List<ValidationMessage> projectPlanFileUrlMessage = new List<ValidationMessage> ( );
        private byte [ ] projectPlanBytes;
        private List<ValidationMessage> projectPlanBytesMessage = new List<ValidationMessage> ( );
        private List<int> projectManagerIds = new List<int>();
        private List<ValidationMessage> projectManagerIdsMessage = new List<ValidationMessage> ( );
        private float totalWork;
        private List<ValidationMessage> totalWorkMessage = new List<ValidationMessage> ( );
        private float actualWork;
        private List<ValidationMessage> actualWorkMessage = new List<ValidationMessage> ( );
        private float projectedWork;
        private List<ValidationMessage> projectedWorkMessage = new List<ValidationMessage> ( );
        private List<string> taskStats = new List<string>();
        private List<ValidationMessage> taskStatsMessage = new List<ValidationMessage> ( );
        private List<string> issueStats = new List<string>();
        private List<ValidationMessage> issueStatsMessage = new List<ValidationMessage> ( );
        private List<string> documentStats = new List<string>();
        private List<ValidationMessage> documentStatsMessage = new List<ValidationMessage> ( );
        private List<string> discussionStats = new List<string>();
        private List<ValidationMessage> discussionStatsMessage = new List<ValidationMessage> ( );
        private bool planDirty;
        private List<ValidationMessage> planDirtyMessage = new List<ValidationMessage> ( );
        private bool tasksDirty;
        private List<ValidationMessage> tasksDirtyMessage = new List<ValidationMessage> ( );
        private bool isSynched;
        private List<ValidationMessage> isSynchedMessage = new List<ValidationMessage> ( );
        private string serverRelativeWebUrl;
        private List<ValidationMessage> serverRelativeWebUrlMessage = new List<ValidationMessage> ( );
        private string lastUpdatedSummaryNote;
        private List<ValidationMessage> lastUpdatedSummaryNoteMessage = new List<ValidationMessage>();
        private bool isWPSandboxActivated;
        private List<ValidationMessage> isWPSandboxActivatedMessage = new List<ValidationMessage>();
        private string wpSandboxNavText;
        private List<ValidationMessage> wpSandboxNavTextMessage = new List<ValidationMessage>();
        

        #endregion

        #region Public Properties

        public DateTime StartDate
        {
            get { return startDate; }
            set
            {
                if ( startDate != value )
                {
                    startDate = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> StartDateMessage
        {
            get { return startDateMessage; }
            set
            {
                if ( startDateMessage != value )
                {
                    startDateMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public DateTime EndDate
        {
            get { return endDate; }
            set
            {
                if ( endDate != value )
                {
                    endDate = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> EndDateMessage
        {
            get { return endDateMessage; }
            set
            {
                if ( endDateMessage != value )
                {
                    endDateMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public ProjectStatus ProjectStatus
        {
            get { return projectStatus; }
            set
            {
                if ( projectStatus != value )
                {
                    projectStatus = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> ProjectStatusMessage
        {
            get { return projectStatusMessage; }
            set
            {
                if ( projectStatusMessage != value )
                {
                    projectStatusMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public TimeMetric TimeMetric
        {
            get { return timeMetric; }
            set
            {
                if ( timeMetric != value )
                {
                    timeMetric = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> TimeMetricMessage
        {
            get { return timeMetricMessage; }
            set
            {
                if ( timeMetricMessage != value )
                {
                    timeMetricMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public string SummaryNote
        {
            get { return summaryNote; }
            set
            {
                if ( summaryNote != value )
                {
                    summaryNote = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> SummaryNoteMessage
        {
            get { return summaryNoteMessage; }
            set
            {
                if ( summaryNoteMessage != value )
                {
                    summaryNoteMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public string ProjectPlanFileUrl
        {
            get { return projectPlanFileUrl; }
            set
            {
                if ( projectPlanFileUrl != value )
                {
                    projectPlanFileUrl = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> ProjectPlanFileUrlMessage
        {
            get { return projectPlanFileUrlMessage; }
            set
            {
                if ( projectPlanFileUrlMessage != value )
                {
                    projectPlanFileUrlMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public byte [ ] ProjectPlanBytes
        {
            get { return projectPlanBytes; }
            set
            {
                if ( projectPlanBytes != value )
                {
                    projectPlanBytes = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> ProjectPlanBytesMessage
        {
            get { return projectPlanBytesMessage; }
            set
            {
                if ( projectPlanBytesMessage != value )
                {
                    projectPlanBytesMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public List<int> ProjectManagerIds
        {
            get { return projectManagerIds; }
            set
            {
                if ( projectManagerIds != value )
                {
                    projectManagerIds = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> ProjectManagerIdsMessage
        {
            get { return projectManagerIdsMessage; }
            set
            {
                if ( projectManagerIdsMessage != value )
                {
                    projectManagerIdsMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public float TotalWork
        {
            get { return totalWork; }
            set
            {
                if ( totalWork != value )
                {
                    totalWork = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> TotalWorkMessage
        {
            get { return totalWorkMessage; }
            set
            {
                if ( totalWorkMessage != value )
                {
                    totalWorkMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public float ActualWork
        {
            get { return actualWork; }
            set
            {
                if ( actualWork != value )
                {
                    actualWork = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> ActualWorkMessage
        {
            get { return actualWorkMessage; }
            set
            {
                if ( actualWorkMessage != value )
                {
                    actualWorkMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public float ProjectedWork
        {
            get { return projectedWork; }
            set
            {
                if ( projectedWork != value )
                {
                    projectedWork = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> ProjectedWorkMessage
        {
            get { return projectedWorkMessage; }
            set
            {
                if ( projectedWorkMessage != value )
                {
                    projectedWorkMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public List<string> TaskStats
        {
            get { return taskStats; }
            set
            {
                if ( taskStats != value )
                {
                    taskStats = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> TaskStatsMessage
        {
            get { return taskStatsMessage; }
            set
            {
                if ( taskStatsMessage != value )
                {
                    taskStatsMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public List<string> IssueStats
        {
            get { return issueStats; }
            set
            {
                if ( issueStats != value )
                {
                    issueStats = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> IssueStatsMessage
        {
            get { return issueStatsMessage; }
            set
            {
                if ( issueStatsMessage != value )
                {
                    issueStatsMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public List<string> DocumentStats
        {
            get { return documentStats; }
            set
            {
                if ( documentStats != value )
                {
                    documentStats = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> DocumentStatsMessage
        {
            get { return documentStatsMessage; }
            set
            {
                if ( documentStatsMessage != value )
                {
                    documentStatsMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public List<string> DiscussionStats
        {
            get { return discussionStats; }
            set
            {
                if ( discussionStats != value )
                {
                    discussionStats = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> DiscussionStatsMessage
        {
            get { return discussionStatsMessage; }
            set
            {
                if ( discussionStatsMessage != value )
                {
                    discussionStatsMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public bool PlanDirty
        {
            get { return planDirty; }
            set
            {
                if ( planDirty != value )
                {
                    planDirty = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> PlanDirtyMessage
        {
            get { return planDirtyMessage; }
            set
            {
                if ( planDirtyMessage != value )
                {
                    planDirtyMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public bool TasksDirty
        {
            get { return tasksDirty; }
            set
            {
                if ( tasksDirty != value )
                {
                    tasksDirty = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> TasksDirtyMessage
        {
            get { return tasksDirtyMessage; }
            set
            {
                if ( tasksDirtyMessage != value )
                {
                    tasksDirtyMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public bool IsSynched
        {
            get { return isSynched; }
            set
            {
                if ( isSynched != value )
                {
                    isSynched = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> IsSynchedMessage
        {
            get { return isSynchedMessage; }
            set
            {
                if ( isSynchedMessage != value )
                {
                    isSynchedMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public string ServerRelativeWebUrl
        {
            get { return serverRelativeWebUrl; }
            set
            {
                if ( serverRelativeWebUrl != value )
                {
                    serverRelativeWebUrl = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> ServerRelativeWebUrlMessage
        {
            get { return serverRelativeWebUrlMessage; }
            set
            {
                if ( serverRelativeWebUrlMessage != value )
                {
                    serverRelativeWebUrlMessage = value;
                    UpdateEntity ( );
                }
            }
        }


        public string LastUpdatedSummaryNote
        {
            get { return lastUpdatedSummaryNote; }
            set
            {
                if (lastUpdatedSummaryNote != value)
                {
                    lastUpdatedSummaryNote = value;
                    UpdateEntity ( );
                }
            }
        }
        public List<ValidationMessage> LastUpdatedSummaryNoteMessage
        {
            get { return lastUpdatedSummaryNoteMessage; }
            set
            {
                if (lastUpdatedSummaryNoteMessage != value)
                {
                    lastUpdatedSummaryNoteMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public bool IsWPSandboxActivated
        {
            get { return isWPSandboxActivated; }
            set
            {
                if (isWPSandboxActivated != value)
                {
                    isWPSandboxActivated = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> IsWPSandboxActivatedMessage
        {
            get { return isWPSandboxActivatedMessage; }
            set
            {
                if (isWPSandboxActivatedMessage != value)
                {
                    isWPSandboxActivatedMessage = value;
                    UpdateEntity();
                }
            }
        }

        public string WPSandboxNavText
        {
            get { return wpSandboxNavText; }
            set
            {
                if (wpSandboxNavText != value)
                {
                    wpSandboxNavText = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> WPSandboxNavTextMessage
        {
            get { return wpSandboxNavTextMessage; }
            set
            {
                if (wpSandboxNavTextMessage != value)
                {
                    wpSandboxNavTextMessage = value;
                    UpdateEntity();
                }
            }
        }
        #endregion

        #region IEntity Members


        public new bool IsValid ( )
        {
            return AllValidationErrors ( ).Count == 0;
        }

        public new List<ValidationMessage> AllValidationErrors ( )
        {
            List<ValidationMessage> allErrors = new List<ValidationMessage> ( );

            allErrors.AddRange ( TitleMessage );
            allErrors.AddRange ( StartDateMessage );
            allErrors.AddRange ( EndDateMessage );
            allErrors.AddRange ( DescriptionMessage );
            allErrors.AddRange ( ProjectStatusMessage );
            allErrors.AddRange ( TimeMetricMessage );
            allErrors.AddRange ( SummaryNoteMessage );
            allErrors.AddRange ( ProjectPlanFileUrlMessage );
            allErrors.AddRange ( ProjectPlanBytesMessage );
            allErrors.AddRange ( ProjectManagerIdsMessage );
            allErrors.AddRange ( TotalWorkMessage );
            allErrors.AddRange ( ActualWorkMessage );
            allErrors.AddRange ( ProjectedWorkMessage );
            allErrors.AddRange ( TaskStatsMessage );
            allErrors.AddRange ( IssueStatsMessage );
            allErrors.AddRange ( DocumentStatsMessage );
            allErrors.AddRange ( DiscussionStatsMessage );
            allErrors.AddRange ( PlanDirtyMessage );
            allErrors.AddRange ( TasksDirtyMessage );
            allErrors.AddRange ( IsSynchedMessage );
            allErrors.AddRange(ServerRelativeWebUrlMessage);
            allErrors.AddRange(IsWPSandboxActivatedMessage);
            allErrors.AddRange(WPSandboxNavTextMessage);

            return allErrors;
        }

        public new void ClearValidationMessages ( )
        {
            TitleMessage.Clear ( );
            StartDateMessage.Clear ( );
            EndDateMessage.Clear ( );
            DescriptionMessage.Clear ( );
            ProjectStatusMessage.Clear ( );
            TimeMetricMessage.Clear ( );
            SummaryNoteMessage.Clear ( );
            ProjectPlanFileUrlMessage.Clear ( );
            ProjectPlanBytesMessage.Clear ( );
            ProjectManagerIdsMessage.Clear ( );
            TotalWorkMessage.Clear ( );
            ActualWorkMessage.Clear ( );
            ProjectedWorkMessage.Clear ( );
            TaskStatsMessage.Clear ( );
            IssueStatsMessage.Clear ( );
            DocumentStatsMessage.Clear ( );
            DiscussionStatsMessage.Clear ( );
            PlanDirtyMessage.Clear ( );
            TasksDirtyMessage.Clear ( );
            IsSynchedMessage.Clear ( );
            ServerRelativeWebUrlMessage.Clear();
            IsWPSandboxActivatedMessage.Clear();
            WPSandboxNavTextMessage.Clear();
        }

        #endregion
    }
}

/*************************************************************************
 * 
 * $Log: /Internal Projects/Kiiro/Kiiro.Common/Entities/Project.cs $
 * 
 * 5     29/09/09 12:40p Shafia
 * Implemented WebPart at project level
 * 
 * 4     31/08/09 12:17p Shafia
 * added the LastUpdatedSummaryNote Property
 * 
 * 3     17/08/09 10:38a Camerons
 * Added check-in comments section
 * 
 ************************************************************************/